package com.jackie.easyble.ui.adapter

import android.content.Context
import android.view.ViewGroup
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.DataBindingHolder
import com.jackie.easyble.R
import com.jackie.easyble.databinding.AdapterAdvertiseUuidItemBinding
import com.sscl.baselibrary.utils.toHexStringWithSpace
import com.sscl.easyble.advertise.AdvertiseUuid

class AdvertiseUuidRecyclerViewAdapter :
    BaseQuickAdapter<AdvertiseUuid, AdvertiseUuidRecyclerViewAdapter.ViewHolder>() {

    class ViewHolder(parent: ViewGroup) :
        DataBindingHolder<AdapterAdvertiseUuidItemBinding>(
            R.layout.adapter_advertise_uuid_item,
            parent
        )

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * 实现此方法，并使用 [holder] 完成 item 视图的操作
     *
     * @param holder A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    override fun onBindViewHolder(holder: ViewHolder, position: Int, item: AdvertiseUuid?) {
        val advertiseUuid = item ?: return
        holder.binding.uuidTv.text = advertiseUuid.parcelUuid.toString()
        holder.binding.uuidDataTv.text = advertiseUuid.data.toHexStringWithSpace()
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        return ViewHolder(parent)
    }
}